<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>授权页面</title>
    <style>
        .auth-btn{
            width: 90%; height: 50px; line-height: 50px; text-align: center; color: #fff;
            font-size: 18px; margin: 50px auto 0 auto; background: #07c160;
        }
    </style>
    <script src="js/jquery.min.js"></script>
    <script src="js/layer/mobile/layer.js"></script>
</head>
<body>
    <div onclick="auth()" class="auth-btn">点击授权</div>
</body>
</html>
<script src="js/config.js?v=8"> </script>
<script>

    function getPreAuthCode () {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: appUrl + "/common/api/app/weChatServer/componentPreauthcode",
                data: {
                   
                },
                dataType: "json",
                success: function (data) {
                    
                    resolve(data.preauthcode)
                }
            });
        })
    }

    function auth () {
        layer.open({type: 2, shadeClose: false});
        getPreAuthCode().then(res => {
          
            var pre_auth_code = res
            var redirect_uri = location.href.replace('threePartyAdminAuth', 'threePartyAdminAuthSuccess')
            
            // var url = 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=' + component_appid + '&pre_auth_code=' + pre_auth_code + '&redirect_uri=' + redirect_uri
            var url = 'https://mp.weixin.qq.com/safe/bindcomponent?action=bindcomponent&no_scan=1&component_appid=' + component_appid + '&pre_auth_code=' + pre_auth_code + '&redirect_uri=' + redirect_uri + '&auth_type=3#wechat_redirect'
            location.href = url
        })
        
    }
</script>